summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt
blob: a48ef7a88a1131cd327cd09a887430637e5da615 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later

package org.yuzu.yuzu_emu.model

import android.net.Uri
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
import org.yuzu.yuzu_emu.YuzuApplication
import org.yuzu.yuzu_emu.utils.GameHelper

class HomeViewModel : ViewModel() {
    private val _navigationVisible = MutableLiveData<Pair<Boolean, Boolean>>()
    val navigationVisible: LiveData<Pair<Boolean, Boolean>> get() = _navigationVisible

    private val _statusBarShadeVisible = MutableLiveData(true)
    val statusBarShadeVisible: LiveData<Boolean> get() = _statusBarShadeVisible

    private val _shouldPageForward = MutableLiveData(false)
    val shouldPageForward: LiveData<Boolean> get() = _shouldPageForward

    private val _gamesDir = MutableLiveData(
        Uri.parse(
            PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
                .getString(GameHelper.KEY_GAME_PATH, "")
        ).path ?: ""
    )
    val gamesDir: LiveData<String> get() = _gamesDir

    var navigatedToSetup = false

    init {
        _navigationVisible.value = Pair(false, false)
    }

    fun setNavigationVisibility(visible: Boolean, animated: Boolean) {
        if (_navigationVisible.value?.first == visible) {
            return
        }
        _navigationVisible.value = Pair(visible, animated)
    }

    fun setStatusBarShadeVisibility(visible: Boolean) {
        if (_statusBarShadeVisible.value == visible) {
            return
        }
        _statusBarShadeVisible.value = visible
    }

    fun setShouldPageForward(pageForward: Boolean) {
        _shouldPageForward.value = pageForward
    }

    fun setGamesDir(activity: FragmentActivity, dir: String) {
        ViewModelProvider(activity)[GamesViewModel::class.java].reloadGames(true)
        _gamesDir.value = dir
    }
}